package 力扣日常刷题.木22二月.第09天215;

/**
 * @author 帅小伙
 * @date 2022/2/15
 * @description
 */
public class Demo66多数元素 {

    public int majorityElement(int[] nums) {
        int count = 1;
        int ans = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if(count == 0) {
                ans = nums[i];
                count++;
            }else{
                if(ans == nums[i]) count++;
                else count--;
            }
        }
        return ans;
    }

}
